﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 委托实例
{
    public delegate void MyDelegate(string name);     //定义委托类型
    class Program
    {
        public static void ChineseGreeting(string name)
        {
            Console.WriteLine("早上好" + name);
        }
        public static void EnglishGreeting(string name)
        {
            Console.WriteLine("good morning");
        }
        public static void Greeting(string name, MyDelegate a)   //定义委托处理方法
        {
            a(name);
        }
        static void Main(string[] args)
        {
            MyDelegate delegate1 = new MyDelegate(ChineseGreeting);  //委托对象指向的方法
            delegate1 += new MyDelegate(EnglishGreeting);     //委托对象指向的方法，此处多个方法绑定在一个委托对象上
            Greeting("xiaozhang", delegate1);
        }
    }
}
